import akshare as ak 
import pandas as pd 
 
# 定义股票代码列表（示例）
stock_codes = ["002240","600366","605136","002210","002277",'002512',"000507","600279","002255","603200","002575","000541","600505","601606","600986","002460","000690","002251","603969","002383","600278","002204","159915","000417", "002345"]
 
# 获取实时数据 
df = ak.stock_zh_a_spot_em() 

# 筛选指定股票代码的数据
selected_data = df[df["代码"].isin(stock_codes)]
target_columns = ["代码", "名称", "涨跌幅","最新价", "换手率","量比", "最低", "最高", "振幅"]
sdata=selected_data[target_columns]
print(sdata)

def get_company_profile(stock_code):
    """获取公司详细信息（来源：巨潮资讯网）"""
    try:
        df = ak.stock_profile_cninfo(symbol=stock_code) #stock_individual_info_em #基础信息
        return df
    except Exception as e:
        print(f"查询失败：{e}")
        return None